<!--
 * @Descripttion: 推广统计
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-05-28 10:46:06
-->
<template>
    <div class="lb-sys-sproconfig">
        <top-nav :title="navTitle" :isBack="true"></top-nav>
        <div class="page-main">
          <el-row class="page-top-operate">
            <lb-button size='medium' type='primary' icon='el-icon-edit' @click="$router.push('/app/present/edit?id=' + searchForm.id)">编辑福利</lb-button>
          </el-row>
          <el-row class="page-search-form">
            <el-form
            :inline="true"
            :model="searchForm"
            ref="searchForm"
            >
              <el-form-item label="员工/用户" prop="is_staff">
                <el-select v-model="searchForm.is_staff" placeholder="请选择">
                    <el-option
                    v-for="item in statusOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="员工姓名/用户昵称" prop="name">
                <el-input v-model="searchForm.name" placeholder="请输入员工姓名/用户昵称"></el-input>
              </el-form-item>
              <el-form-item>
                <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
                <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
              </el-form-item>
            </el-form>
          </el-row>

            <el-table
            v-loading="loading"
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
            <el-table-column
              prop="nickName"
              label="用户昵称">
            </el-table-column>
            <el-table-column
              prop="name"
              label="员工姓名">
            </el-table-column>
            <el-table-column
              prop="share_num"
              label="分享次数">
            </el-table-column>
            <el-table-column
              prop="pv"
              label="浏览次数">
            </el-table-column>
            <el-table-column
              prop="get_num"
              label="领取数">
            </el-table-column>
            <el-table-column
              prop="use_num"
              label="使用数">
            </el-table-column>
            <el-table-column
              label="操作">
                <template slot-scope="scope">
                  <div class="table-operate">
                    <lb-button size='mini' plain type='primary' @click="$router.push('/app/present/detail?id=' + scope.row.active_id + '&uid='+ scope.row.user_id)">{{$t('action.view')}}</lb-button>
                  </div>
                </template>
            </el-table-column>
          </el-table>

        <lb-page
          :batch='false'
          :page='searchForm.page'
          :pageSize='searchForm.limit'
          :total='total'
          @handleSizeChange='handleSizeChange'
          @handleCurrentChange='handleCurrentChange'
          >
        </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      navTitle: '',
      statusOptions: [
        {label: '全部', value: 2},
        {label: '用户', value: 0},
        {label: '员工', value: 1}
      ],
      loading: false,
      total: 0,
      searchForm: {
        is_staff: 2,
        name: '',
        page: 1,
        limit: 10
      },
      tableData: []
    }
  },
  activated () {
    let { id } = this.$route.query
    if (id) {
      this.searchForm.id = id
      this.getTableDataList()
    }
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let {searchForm} = this
      let {code, data} = await this.$api.presentLogList(searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
      this.navTitle = `“${data.active_name}”的推广统计`
    }
  }
}
</script>

<style lang="scss" scoped>
.el-input,
.el-select{
  width: 200px;
}
</style>
